/*app.controller('AppCreateTabCtrl', ['$rootScope', '$scope', 'httpLoad', '$modal', '$stateParams', '$state', function ($rootScope, $scope, httpLoad, $modal, $stateParams, $state) {
    $rootScope.moduleTitle = '应用管理 > 应用构建';
    $rootScope.link = '/statics/css/tpl-card.css';
    $scope.isBack = false;
    var flag = sessionStorage.getItem('appCreatetabLocation')||1;
    switch (flag/1){
        case 1:
            $scope.isappGe = true;
            break;
        case 2:
            $scope.isAppList = true;
            break;
    }
    sessionStorage.setItem('appCreatetabLocation','1');
}]);*/
app.controller('appGeCtrl', ['$rootScope', '$scope', 'httpLoad', '$modal', '$stateParams', '$state',function ($rootScope, $scope, httpLoad, $modal, $stateParams, $state) {
    $rootScope.moduleTitle = '应用管理 > 应用构建';
    $rootScope.link = '/statics/css/tpl-card.css';
    $scope.param = {
        page: 1,
        rows: 9
    };
    //获取
    $scope.getData = function (page) {
        $scope.param.page = page || $scope.param.page;
        $scope.showDetail = false;
        var params = {
            page: $scope.param.page,
            rows: $scope.param.rows,
            projectName:$scope.searchByAppname
        };
        // $scope.param.warehouseId = $stateParams.id;
        httpLoad.loadData({
            url: '/pipeline/pipeline/applications',
            data: params,
            success: function (data) {
                if(data.rows&&data.rows.length!=0){
                    $scope.appList = data.rows;
                    $scope.totalCount = data.records;
                    $scope.isImageData = false;
                }else{
                    $scope.isImageData = true;
                }
            }
        });
    };
    $scope.getData(1);

    $scope.detail = function(item){
        $state.go('app.application.appCreateIn',{id:"1",taskId:item.taskId,name:item.projectName,flag:0});
    }

    $scope.add = function(){  //打开模态
        var modalInstance = $modal.open({
            templateUrl : '/statics/tpl/application/create/createAppName.html',
            controller : 'addAppNameModalCtrl'// 初始化模态范围
        });
        modalInstance.result.then(function(){
        },function(){});
    };
}])

//新增ctrl
angular.module('app').controller('addAppNameModalCtrl',['$scope','$modalInstance','LANGUAGE','httpLoad','$state',
    function($scope,$modalInstance,LANGUAGE,httpLoad,$state){
        $scope.appData={
            "applicationCore.applicationRuntimeId":1,
            "applicationCore.applicationCoreUsername":"default",
            "applicationCore.applicationCoreType":"kubernetes"
        }
        $scope.ok = function(){
            httpLoad.loadData({
                url:'/application/createRawApplication.do',
                data: $scope.appData,
                success:function(data){
                    if(data.success){
                        $state.go('app.application.appCreateIn',{id:data.applicationCoreId,name:data.applicationCoreName,flag:0});
                        $modalInstance.close();
                    }
                }
            });
        };
        $scope.cancel = function(){
            $modalInstance.dismiss('cancel'); // 退出
        };
    }]);